package com.zh.view

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.ComposeWindow
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.unit.dp
import com.zh.view.component.CustomSnackbarHost
import com.zh.view.component.NavigationSidebar
import com.zh.view.data.ElMessage


// 柔和米白色（多种选择）
val offWhite = Color(0xFFF9F6EE)     // 经典米白

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AppLayoutScene(window: ComposeWindow) {
    val scope = rememberCoroutineScope()
    // 初始化单例
    LaunchedEffect(Unit) {
        ElMessage.init(scope)
    }

    Scaffold(snackbarHost = { CustomSnackbarHost(ElMessage.snackbarState) }) { _ ->
        var selectedItem by remember { mutableStateOf("create") }

        // 桌面端使用永久显示的侧边栏
        Row(modifier = Modifier.fillMaxSize()) {
            // 左侧导航栏
            NavigationSidebar(
                items = menuItems,
                selectedItemRoute = selectedItem,
                onItemSelected = { selectedItem = it },
                modifier = Modifier.fillMaxHeight(),
                showIconsOnly = false,
            )

            //右侧内容区域
            Box(
                modifier = Modifier.fillMaxSize()
                    .background(offWhite.copy(alpha = 0.8f))
                    .shadow(
                        elevation = 1.dp,
                        shape = RectangleShape,
                        ambientColor = Color.Black.copy(alpha = 0.05f),
                        spotColor = Color.Black.copy(alpha = 0.05f)
                    )
                    .padding(start = 1.dp)
            ) {
                router(selectedItem, window)
            }
        }
    }
}


